<template>
    <div class="login-container">
        图像管理
    </div>
</template>

<script>
import { login } from '@/api/user.js'
import { getMenuAuth } from '@/api/permission.js'
export default {
  name: 'login',
  data () {
    return {
      loginForm: {
        cuserid: '',
        cpswd: ''
      },
      loginRules: {
        cuserid: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
        cpswd: [{ required: true, trigger: 'blur', message: '请输入密码' }]
      },
      loading: false,
      pwdType: 'password',
      sid: ''
    }
  },
  methods: {
    showPwd () {
      if (this.pwdType === 'password') {
        this.pwdType = ''
      } else {
        this.pwdType = 'password'
      }
    },
    handleLogin () {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          login({ cuserid: '13668152387', cpswd: '123456' }).then((data) => {
            this.loading = false
            if (data.result === 1) {
              this.$store.dispatch('setSid', data.sessionid)
              this.$store.dispatch('setUserInfo', data.data.user)
            }
          }).then(() => {
            getMenuAuth().then((data) => {
              this.$store.dispatch('setMenu', data.data)
            })
          }).then(() => {
            setTimeout(() => {
              this.$router.push({ path: '/' })
            }, 1000)
          })
            .catch((err) => {
              this.loading = false
              console.log(err)
            })
        } else {
          return false
        }
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
$bg:#fff;
$dark_gray:#889aa4;
$light_gray:#eee;
</style>
